<template>
  <div class="xmgl-page">
    <page-header title="退出登录" @back="logout">
      <template slot="content">
        <div style="margin-right: 20px">{{ yhxx.mc }}</div>
        <el-link type="primary" @click="$router.push('/doc')">文档</el-link>
      </template>
    </page-header>
    <el-tabs v-model="tab" style="height: 200px;" tab-position="top">
      <el-tab-pane name="xmgl" label="项目管理">
        <xmgl v-if="tab==='xmgl'"/>
      </el-tab-pane>
      <el-tab-pane name="sjygl" label="数据源管理">
        <sjygl v-if="tab==='sjygl'"/>
      </el-tab-pane>
      <el-tab-pane name="wbffgl" label="外部方法管理">
        <wbffgl v-if="tab==='wbffgl'"/>
      </el-tab-pane>
      <el-tab-pane name="yhgl" label="用户管理" v-if="isAdmin">
        <yhgl v-if="tab==='yhgl'"/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import PageHeader from "@/components/PageHeader";
import Xmgl from "@/components/Xmgl";
import Sjygl from "@/components/Sjygl";
import Yhgl from "@/components/Yhgl";
import Wbffgl from "@/components/Wbffgl";
import commonMixins from "@/mixins/commonMixins";

export default {
  mixins: [commonMixins],
  name: "Xtmh",
  components: {Xmgl, Sjygl, PageHeader, Yhgl, Wbffgl},
  data() {
    return {
      tab: ''
    }
  },
  watch: {
    tab(val) {
      mySessionStorage.setItem("xtmh-tab", val)
    }
  },
  mounted() {
    this.tab = mySessionStorage.getItem("xtmh-tab", 'xmgl')
  },
  methods: {
    async logout() {
      try {
        await this.$confirm("是否退出登录？")
        mySessionStorage.setItem("yhxx", null)
        if (this.tab === 'yhgl') {
          mySessionStorage.setItem("xtmh-tab", 'xmgl')
        }
        this.$router.replace("/login")
      } catch (e) {
        if ("cancel" === e) return
        this.$message({message: "退出登录失败" + e.message, type: "error"})
      }
    },
  }
}
</script>
